<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<title>view/workArea/parts/applyPartsList</title>
		<!-- css代码 start -->
		<link href="../../../css/mui.min.css" rel="stylesheet" />
		<link href="../../../css/global.css" rel="stylesheet" />
		<link href="../../../css/style.css" rel="stylesheet" />
		<link href="../../../css/checkbox.css" rel="stylesheet" />
		<style>
			#div {
				width: 0px;
				height: 0px;
				background: red;
				position: fixed;
				top: 70%;
				left: 50%;
			}
					
			/*移除底部或顶部三角,需要在删除此代码*/
			.mui-popover .mui-popover-arrow:after {
				width: 0px;
			}
			.btn_box {
				overflow: hidden;
			}
		</style>
		<!-- css代码 end -->
	</head>
	<body>
		<div id="div"></div>
		<div id="popover" class="mui-popover shadow popover">
			<p class="title" id="title">您确定要删除该备件信息吗？</p>
			<div class="btn_box">
				<span class="fl" onclick="closePopover()">取消</span>
				<span class="fr red" onclick="removePart()">确定</span>
			</div>
		</div>
		<!-- html代码 start -->
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 id="title" class="mui-title">备件列表</h1>
		</header>
		<div class="mui-content">
			<div class="item_box" id="itemBox">
				<div class="nodata">—— 暂无数据 ——</div>
				<!-- <div class="item">
					<div class="bar">
						<span class="del">删除</span>
						<span class="number">1170001<img src="../../../images/icon_204.png" /></span>
					</div>
					<div class="text">
						<span class="l">备件名称：</span> 
						备件1
					</div>
					<div class="type">
						<p>备件数量：<span>2020-01-20</span><img src="../../../images/icon_217.png"/></p>
						<p>借货单号：<span>待接收</span><img src="../../../images/icon_218.png"/></p>
						<p>借货用户名称：<span>待接收</span><img src="../../../images/icon_201.png"/></p>
					</div>
				</div> -->
			</div>
		</div>
		<!-- html代码 end -->

		<!-- js代码 start -->

		<!-- 基础js start -->
		<script src="../../../js/mui.min.js"></script>
		<script src="../../../js/utils/h.js"></script>
		<script src="../../../js/constant.js"></script>
		<script src="../../../js/common.js"></script>
		<script src="../../../js/utils/base64.js"></script>
		<script src="../../../js/utils/md5.js"></script>
		<script src="../../../js/utils/sortMap.js"></script>
		<script src="../../../js/utils/http.js"></script>
		<script src="../../../js/app.js"></script>
		<!-- 基础js end -->

		<script type="text/javascript" charset="utf-8">
			var applyPartsKey = "FSE_ITEM_KEY_APPLY_PARTS";
			var removePart;
			var toEdit;
			var khInfo;
			var itemIndex;
			
			var data1=[{"text":"保外借用","value":"1"},{"text":"保内借用","value":"2"},{"text":"服务合同","value":"4"}];
			var data2=[{"text":"个人维修工具","value":"6"},{"text":"备件库存","value":"7"},{"text":"耗材销售","value":"8"}];
			var data3=[{"text":"返库维修","value":"5"}];
			
			(function($, doc) {
				$.init();
				$.plusReady(function() {
					// 上页参数
					var self = plus.webview.currentWebview();
					khInfo = self.khInfo;	
					khInfo.Type = self.Type;
					

					
					/**
					 * 删除备件
					 * @param {Object} itemIndex 缓存数组中的下标
					 */
					removePart = function() {
						mui("#popover").popover('toggle', document.getElementById("div"));
						// 根据下标移除
						itemsArr.splice(itemIndex, 1);
						// 重置缓存
						h.setItem(applyPartsKey, JSON.stringify(itemsArr));
						// 刷新列表页
						showItems();
						itemIndex = ''
					}
					
					/**
					 * 修改备件
					 * @param {Object} itemIndex 缓存数组中的下标
					 * @param {Object} partNo 备件号
					 */
					toEdit = function(itemIndex, partNo) {
						app.jumpTo("applyPartsEdit.html","view/workArea/parts/applyPartsEdit",{
							"itemIndex": itemIndex,
							"partNo": partNo,
							"khInfo": khInfo
						})
					}
					
					// 显示列表
					showItems();
				});
			}(mui, document));
			function closePopover() {
				mui("#popover").popover('toggle', document.getElementById("div"));
			}
			
			function delPart(id) {
				itemIndex = id;
				mui("#popover").popover('toggle', document.getElementById("div"));
			}
			var itemsArr = new Array();
			// 显示列表
			var showItems = function() {
				// 列表数据初始化
				var items = h.getItem(applyPartsKey);
				if (items) {
					itemsArr = JSON.parse(items);
				}
				if (itemsArr.length > 0) {
					var str = ""
					for(var i = 0; i<itemsArr.length; i++){
						// if (khInfo.isWarranty){
						// 	var selectJson = data1.find(function(e){
						// 		return e.text.indexOf(khInfo.isWarranty) !== -1
						// 	})
						// }
						
						var info = itemsArr[i];
						/**
						 * 
						 
						var data,selectJson;
						if (!info.Use_type){
							data = data1
							selectJson = data.find(function(e){
								return e.text.indexOf(khInfo.isWarranty) !== -1
							})
						}else{
							if (info.Type==1) {
								data = data1
							} else if (info.Type==2) {
								data = data2
							} else {
								data = data3
							}
							console.log(JSON.stringify(data))
							selectJson = data.find(function(e){
								 return e.value == info.Use_type
							})
						}
						console.log(JSON.stringify(selectJson))
						*/
						str += '<div class="item" id="item_'+ i +'">';
						str += '<div class="bar">';
						str += '<span class="del" onclick="delPart('+ i +')">删除</span>';
						str += '<span class="number" onclick="toEdit('+ i +', \''+ info.Part_no +'\')">';
						str += '<img src="../../../images/icon_204.png" />'+ info.Part_no +'</span>';
						str += '</div>';
						str += '<div class="text" onclick="toEdit('+ i +', \''+ info.Part_no +'\')">';
						str += '<span class="l">备件名称：</span> ' + emptyStr(info.Part_name);
						str += '</div>';
						str += '<div class="type" onclick="toEdit('+ i +', \''+ info.Part_no +'\')">';
						str += '<p><img src="../../../images/icon_217.png"/>备件数量：<span>'+ emptyStr(info.Part_qty) +'</span></p>';
						// str += '<p><img src="../../../images/icon_218.png"/>借货单号：<span>'+ emptyStr(info.Part_DebitNo) +'</span></p>';
						str += '<p><img src="../../../images/icon_203.png"/>备件用途：<span>'+ emptyStr(info.userTypeSel) +'</span></p>';
						str += '<p><img src="../../../images/icon_229.png"/>收货地址：<span>'+ emptyStr(info.shipaddress) +'</span></p>';
						str += '<p><img src="../../../images/icon_201.png"/>联系人：<span>'+ emptyStr(info.contactor) +'</span></p>';
						str += '<p><img src="../../../images/icon_220.png"/>手机号：<span>'+ emptyStr(info.Mobile) +'</span></p>';
						str += '<p><img src="../../../images/icon_386.png"/>借货用户名称：<span>'+ emptyStr(info.CustName) +'</span></p>';
						str += '</div>';
						str += '</div>';
					}
					h("#itemBox").html(str);
				} else {
					h("#itemBox").html('<div class="nodata">—— 暂无数据 ——</div>');
				}
			}
		</script>
		<!-- js代码 end -->
	</body>
</html>